package main

/**
  @brief 看板view层
  @author lancelot
  @date 2017/1/16
*/

import (
	"html/template"
	"misakago"
)

func MsgBoardHandler(handler *misakago.Handler) {
	r := handler.Request
	if r.Method == "GET" {
		UpdateBoard(handler)
	} else {
		r.ParseForm()
		msg := r.Form.Get("msg")

		msgboard_service.PushOne(msg)
		UpdateBoard(handler)
	}
}

func UpdateBoard(handler *misakago.Handler) {
	var str string = ""
	msgs := msgboard_service.GetList(10)
	for _, item := range msgs {
		str = str + "<li>" + item.Msg + "</li>"
	}
	handler.RenderTemplate("home.html", map[string]interface{}{"Msgs": template.HTML(str)})
}
